package com.ngu.sys.user.controller;

import com.ngu.sys.user.model.TSysUser;
import com.ngu.sys.user.services.SysUserService;
import com.ngu.util.AjaxResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
* @Description:    用户登录Pc管理
* @Author:         hq
* @CreateDate:     2019/9/28 2019/9/28
* @UpdateUser:     hq
* @UpdateDate:     2019/9/28 2019/9/28
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
@RestController
@RequestMapping("/sys")
public class SysUserController {
    //依赖注入：spring 使用了javaBean的set方法和有参的构造方法，为我们创建了所需对象并将其属性自动设置所需要的值。 这就是依赖注入思想
    @Autowired
    private SysUserService sysUserService;

    /**
    * 查询所有用户信息
    * @author      hq
    * @date        2019/9/28 16:39
    */
    @RequestMapping("/selectUserAll")
    public AjaxResponse SelectSysUserList(TSysUser sysUser){
     Object obj =    sysUserService.findSysUserList(sysUser);
     return    AjaxResponse.success("请求成功！");

    }

    /**
     * 登录
     * @author      hq
     * @date        2019/9/28 16:39
     */
    @RequestMapping("/login")
    public AjaxResponse userLogin(TSysUser sysUser, HttpSession session){
        return  sysUserService.userLogin(sysUser,session);
    }

    /**
     * 获取登录信息
     * @param request
     * @return
     */
    @GetMapping("/getCurrentUserInfo")
    public AjaxResponse getCurrentUserInfo(HttpServletRequest request){
       return AjaxResponse.success("请求成功","200",request.getSession().getAttribute("SysUser"));


    }


    /**
    * 退出登录
    * @author      hq
    * @date        2019/10/2 18:56
    */
    @RequestMapping("/logout")
    public AjaxResponse loginOut(HttpSession session){
        return  sysUserService.loginOut(session);
    }




}
